<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="showConfImg"
    :append-to-body="true"
    :close-on-click-modal="false"
    :show-close="true"
    :before-close="clear"
    title="体验门店图片维护"
    width="80%"
  >
    <ImgItemSingle :file-list="fileList" :size-tips="fileSize" @uploaded="uploadedSucc" />
    <div slot="footer" class="dialog-footer" style="text-align: center">
      <el-button type="text">
        <i class="el-icon-search magnifier" />
      </el-button>
      <el-button :disabled="fullscreenLoading" :loading="fullscreenLoading" type="primary" @click="save">确 定</el-button>
      <el-button @click="clear">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getConfImg, updateConfImg } from '@/api/vehicle/dealer.js'
import formMixins from '@/mixins/formMixins'
import ImgItemSingle from '@/components/uploads/ImgItemSingle'

export default {
  name: 'DealerIndex',
  components: {
    ImgItemSingle
  },
  mixins: [formMixins],
  props: {
    showConfImg: Boolean
  },
  data() {
    return {
      fileSize: [
        { item: '1125px*648px' }
      ],
      fullscreenLoading: false,
      // url: '',
      fileList: []

    }
  },
  computed: {
  },

  watch: {
    'search.province': function(val) {
      console.log(val)
      if (!val) {
        this.cityOptions = []
        this.search.city = ''
      }
    }
  },

  mounted() {
    getConfImg().then(res => {
      console.log(res)
      this.fileList.push({ file_url: res })
      // this.url = res
    })
    // console.log(this.provinceOptions)
  },
  methods: {

    save() {
      if (!this.fileList || this.fileList.length == 0) {
        this.$message({
          type: 'warning',
          message: '请上传图片'
        })
        return false
      }
      if (!this.fileList[0].file_upload_info_id) {
        this.$message({
          type: 'warning',
          message: '若修改，请重新上传后保存！'
        })
        return false
      }
      updateConfImg({ img_url: this.fileList[0].file_url, file_upload_info_id: this.fileList[0].file_upload_info_id }).then(res => {
        this.$message({
          type: 'success',
          message: '保存成功'
        })
        this.saveLoading = false
        this.clear()
      })
        .catch(err => {
          console.log(err)
          this.saveLoading = false
        })
    },
    clear() {
      this.$emit('update:showConfImg', false)
    }
  }
}
</script>

<style scoped>

</style>
